package com.bgs.eat.fileManager.mapper;

import com.bgs.eat.fileManager.entity.FileEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface FileMapper {


    /**
     * 上传附件信息
     * @param fileEntity
     * @return
     */
    @Insert("insert into file_manager(file_name,file_path,file_size,file_suffix,del_flag,file_encryption_name,create_time,update_time)" +
            "values(#{fileName},#{filePath},#{fileSize},#{fileSuffix},#{delFlag},#{fileEncryptionName},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id")
    Integer uploadFile(FileEntity fileEntity);

    /**
     * 根据Id获取图片信息
     * @param id
     * @return
     */
    @Select("select * from file_manager where del_flag = 1 and id = #{id}")
    @Results({
            @Result(property = "fileName",column = "file_name"),
            @Result(property = "filePath",column = "file_path"),
            @Result(property = "fileSize",column = "file_size"),
            @Result(property = "fileSuffix",column = "file_suffix"),
            @Result(property = "fileEncryptionName",column = "file_encryption_name"),
            @Result(property = "delFlag",column = "del_flag"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
    })
    FileEntity getImageById(Integer id);


    /**
     * 根据id进行逻辑删除
     * @return
     */
    @Update("update file_manager set del_flag=0 where id = #{avartarId}")
    Integer deleteById(Integer avartarId);
}
